package com.springbatch.springbatch.filetodb;

import com.springbatch.springbatch.bo.Person;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.validation.BindException;

public class PersonFieldSetMapper implements FieldSetMapper<Person> {
   @Override
   public Person mapFieldSet(FieldSet fieldSet) throws BindException {

       //"ID,lastName,firstName,position,birthYear, debutYear"
        Person person = new Person();
        person.setId(fieldSet.readString(0));
        person.setLastName(fieldSet.readString(1));
        person.setFirstName(fieldSet.readString(2));
        person.setPosition(fieldSet.readString(3));
        person.setBirthYear(fieldSet.readInt(4));
        person.setDebutYear(fieldSet.readInt(5));

//       person.setId(fieldSet.readString("ID"));
//       person.setLastName(fieldSet.readString("lastName"));
//       person.setFirstName(fieldSet.readString("firstName"));
//       person.setPosition(fieldSet.readString("position"));
//       person.setBirthYear(fieldSet.readInt("birthYear"));
//       person.setDebutYear(fieldSet.readInt("debutYear"));

        return person;
    }
}
